 //抛出混入对象，方便外部访问
export default {
 data(){
     return { 
        isBackStage:false,
        screenWidth:document.documentElement.clientWidth
     }
 },
 methods: {
  // 适配为rem设置的 remUnit: 3840
  getRealPX (px) {
    let nowClientWidth = document.documentElement.clientWidth;
    let size = this.nowSize(px,nowClientWidth)
    return size
  },
  // 换算方法
  nowSize  (val,nowClientWidth, initWidth = 1920) {
    return val * (nowClientWidth / initWidth);
  },
  changeWidth(callback){
    let self = this;
    window.onresize = function(){ // 定义窗口大小变更通知事件
        let _isMobile = self._isMobile()
        if(_isMobile){
          let screenWidth = document.documentElement.clientWidth; //窗口宽度 
          if(self.screenWidth!=screenWidth){
            self.screenWidth = screenWidth
            if(callback){
              callback()
            }
          }
        }
    }; 
  },
  //App.vue
  _isMobile() {
    let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
    return flag;
  }
 }
}
